<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Templatemini extends Model
{
    protected $table = 'template_mini';
    protected $primaryKey = 'id';

    public static function templateMiniLists($users_id)
    {
        return self::where("users_id",$users_id)->where("disable",1)->get();
    }

    public static function userTemplateMini($users_id)
    {
        return self::select("id","enterprise_name","corp_type")->where("users_id",$users_id)->where("disable",1)->get();
    }

    public static function templateMiniCount($users_id)
    {
        return self::where("users_id",$users_id)->where("disable",1)->count("id");
    }

    public static function templateMiniByName($users_id,$enterprise_name)
    {
        return self::where("users_id",$users_id)->where("enterprise_name",$enterprise_name)->where("disable",1)->first();
    }

    public static function templateMiniDisable($id,$disable)
    {
        return self::where("id",$id)->update(["disable"=>$disable]);
    }

    public static function templateMiniDetial($id)
    {
        return self::where("id",$id)->first();
    }

    public static function templateMiniUpdate($id,$enterprise_name,$code_type,$code,$legal_persona_wechat,$legal_persona_name)
    {
        return self::where("id",$id)->update(["enterprise_name"=>$enterprise_name,"code_type"=>$code_type,"code"=>$code,"legal_persona_wechat"=>$legal_persona_wechat,"legal_persona_name"=>$legal_persona_name]);
    }

    public static function templateMiniInsert($users_id,$enterprise_name,$code_type,$code,$legal_persona_wechat,$legal_persona_name,$corp_image="")
    {
        return self::insert(["users_id"=>$users_id,"enterprise_name"=>$enterprise_name,"code_type"=>$code_type,"code"=>$code,"legal_persona_wechat"=>$legal_persona_wechat,"legal_persona_name"=>$legal_persona_name,"corp_image"=>$corp_image,"created_at"=>time()]);
    }

    public static function userJsTemplateMini($users_id)
    {
        return self::select("id","enterprise_name","corp_type","code_type","code","legal_persona_wechat","legal_persona_name")->where("users_id",$users_id)->whereIn('corp_type',[1,2])->where("disable",1)->get();
    }
}
